/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aqu.persistencia.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Verito Ramirez
 *         Victor Jaramillo
 */
@Entity
@Table(name = "cxp_retencion")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CxpRetencion.findAll", query = "SELECT s FROM CxpRetencion s"),
    @NamedQuery(name = "CxpRetencion.findBycxpCodigoRet", query = "SELECT s FROM CxpRetencion s WHERE s.cxpCodigoRet = :cxpCodigoRet"),
    @NamedQuery(name = "CxpRetencion.findBycxpNombreRet", query = "SELECT s FROM CxpRetencion s WHERE s.cxpNombreRet = :cxpNombreRet"),
    @NamedQuery(name = "CxpRetencion.findBycxpCodAlternoRet", query = "SELECT s FROM CxpRetencion s WHERE s.cxpCodAlternoRet = :cxpCodAlternoRet"),
    @NamedQuery(name = "CxpRetencion.findBycxpCodAlterno1Ret", query = "SELECT s FROM CxpRetencion s WHERE s.cxpCodAlterno1Ret = :cxpCodAlterno1Ret"),
    @NamedQuery(name = "CxpRetencion.findBycxpCodigoTipRet", query = "SELECT s FROM CxpRetencion s WHERE s.cxpCodigoTipRet = :cxpCodigoTipRet")})
public class CxpRetencion implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "CXP_CODIGO_RET")
    private String cxpCodigoRet;
    @Size(max = 300)
    @Column(name = "CXP_NOMBRE_RET")
    private String cxpNombreRet;
    @Size(max = 45)
    @Column(name = "CXP_CODALTERNO_RET")
    private String cxpCodAlternoRet;
    @Size(max = 45)
    @Column(name = "CXP_CODALTERNO1_RET")
    private String cxpCodAlterno1Ret;
    @JoinColumn(name = "CXP_CODIGO_TIPRET", referencedColumnName = "CXP_CODIGO_TIPRET")
    @ManyToOne(optional = false)
    private CxpTipoRetencion cxpCodigoTipRet;
    
    public CxpRetencion() {
    }

    public CxpRetencion(String cxpCodigoRet, String cxpNombreRet, String cxpCodAlternoRet, String cxpCodAlterno1Ret, CxpTipoRetencion cxpCodigoTipRet) {
        this.cxpCodigoRet = cxpCodigoRet;
        this.cxpNombreRet = cxpNombreRet;
        this.cxpCodAlternoRet = cxpCodAlternoRet;
        this.cxpCodAlterno1Ret = cxpCodAlterno1Ret;
        this.cxpCodigoTipRet = cxpCodigoTipRet;
    }

    public String getCxpCodAlterno1Ret() {
        return cxpCodAlterno1Ret;
    }

    public void setCxpCodAlterno1Ret(String cxpCodAlterno1Ret) {
        this.cxpCodAlterno1Ret = cxpCodAlterno1Ret;
    }

    public String getCxpCodAlternoRet() {
        return cxpCodAlternoRet;
    }

    public void setCxpCodAlternoRet(String cxpCodAlternoRet) {
        this.cxpCodAlternoRet = cxpCodAlternoRet;
    }

    public String getCxpCodigoRet() {
        return cxpCodigoRet;
    }

    public void setCxpCodigoRet(String cxpCodigoRet) {
        this.cxpCodigoRet = cxpCodigoRet;
    }

    public CxpTipoRetencion getCxpCodigoTipRet() {
        return cxpCodigoTipRet;
    }

    public void setCxpCodigoTipRet(CxpTipoRetencion cxpCodigoTipRet) {
        this.cxpCodigoTipRet = cxpCodigoTipRet;
    }



    public String getCxpNombreRet() {
        String nombreTemp = "";
        int tamanoNombre = 0;
        if((cxpNombreRet != null)){
            if(cxpNombreRet.length()>0){
                tamanoNombre = cxpNombreRet.length();
                if(tamanoNombre >= 40){                
                    nombreTemp = cxpNombreRet.substring(0, 40);
                }else
                    nombreTemp = cxpNombreRet.substring(0, tamanoNombre);
            }            
        }
        return nombreTemp;
    }

    public void setCxpNombreRet(String cxpNombreRet) {
        this.cxpNombreRet = cxpNombreRet;
    }

   
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cxpCodigoRet != null ? cxpCodigoRet.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CxpRetencion)) {
            return false;
        }
        CxpRetencion other = (CxpRetencion) object;
        if ((this.cxpCodigoRet == null && other.cxpCodigoRet != null) || (this.cxpCodigoRet != null && !this.cxpCodigoRet.equals(other.cxpCodigoRet))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "clases.CxpRetencion[ cxpCodigoRet=" + cxpCodigoRet + " ]";
    }
    
}
